﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using FA.Library.Plugin;
using FA.FlightAttendant.Plugin;
using FA.FlightAttendant.View.Windows;
using FA.FlightAttendant.ViewModel.Windows;

namespace FA.FlightAttendant.View.Commands
{
    public class EditSimulatorCommand : ICommand
    {
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            Simulator simulator = (Simulator)parameter;

            // Get the simulator info
            NewSimulatorInfo simInfo = new NewSimulatorInfo();
            simInfo.Name = simulator.Name;
            simInfo.OriginalName = simulator.Name; // Setting the 'original name' indicates that we're in 'edit mode'
            simInfo.Plugin = PluginFactory.Instance.GetPluginLibrary(simulator.Plugin.GetType().ToString());
            simInfo.Settings = PluginSetting.ConvertFromDictionary(simulator.Plugin.GetSettings());

            // Update the view model
            NewSimulatorWindow window = new NewSimulatorWindow();
            NewSimulatorVM viewModel = (NewSimulatorVM)window.DataContext;
            viewModel.SimulatorInfo = simInfo;
            
            window.ShowDialog();
        }

        public bool CanExecute(object parameter)
        {
            return (parameter != null) && (parameter is Simulator);
        }
    }
}